package com.atguigu.exam;

import java.io.*;

/**
 * 利用程序复制 test.txt 为 test2.txt
 *
 * @author xbd
 * @create 2021-05-30 16:32
 */
public class CopyTxtCTest {
    public static void main(String[] args) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            br = new BufferedReader(new FileReader("test1.txt"));
            bw = new BufferedWriter(new FileWriter("test2.txt"));
            char[] chars = new char[10];
            int len;
            while ((len = br.read(chars)) != -1) {
                bw.write(chars, 0, len);
                bw.flush();
            }
            System.out.println("复制完成。。。");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
